/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Administrador							
 */
@Entity
@Table(name = "userpharmacy")
@NamedQueries({
    @NamedQuery(name = "Userpharmacy.findAll", query = "SELECT u FROM Userpharmacy u"),
    @NamedQuery(name = "Userpharmacy.findByPharmacyId", query = "SELECT u FROM Userpharmacy u WHERE u.userpharmacyPK.pharmacyId = :pharmacyId"),
    @NamedQuery(name = "Userpharmacy.findByPharmacyIdByActive", query = "SELECT u FROM Userpharmacy u WHERE u.userpharmacyPK.pharmacyId = :pharmacyId AND u.active = :active"),
    @NamedQuery(name = "Userpharmacy.findByUserId", query = "SELECT u FROM Userpharmacy u WHERE u.userpharmacyPK.userId = :userId"),
    @NamedQuery(name = "Userpharmacy.findByUserIdByActive", query = "SELECT u FROM Userpharmacy u WHERE u.userpharmacyPK.userId = :userId AND u.active = :active"),
    @NamedQuery(name = "Userpharmacy.findByUserIdByPharmacyId", query = "SELECT u FROM Userpharmacy u WHERE u.userpharmacyPK.userId = :userId AND u.userpharmacyPK.pharmacyId = :pharmacyId"),
    @NamedQuery(name = "Userpharmacy.findByActive", query = "SELECT u FROM Userpharmacy u WHERE u.active = :active")})
public class Userpharmacy implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UserpharmacyPK userpharmacyPK;
    @Basic(optional = false)
    @Column(name = "active")
    private boolean active;
    @OneToMany(mappedBy = "userpharmacy")
    private Collection<Transaction> transactionCollection;
    @OneToMany(mappedBy = "userpharmacy1")
    private Collection<Transaction> transactionCollection1;
    @OneToMany(mappedBy = "userpharmacy")
    private Collection<Decline> declineCollection;
    @OneToMany(mappedBy = "userpharmacy")
    private Collection<Stock> stockCollection;
    @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Pharmacy pharmacy;
    @JoinColumn(name = "userId", referencedColumnName = "userId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @OneToMany(mappedBy = "userpharmacy")
    private Collection<Accountreceivable> accountreceivableCollection;
    @OneToMany(mappedBy = "userpharmacy")
    private Collection<Transfer> transferCollection;
    @OneToMany(mappedBy = "userpharmacy1")
    private Collection<Transfer> transferCollection1;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userpharmacy",fetch = FetchType.LAZY)
    private Collection<Access> accessCollection;
    
    @OneToMany(mappedBy = "userpharmacy")
    private Collection<Product> productCollection;

    public Userpharmacy() {
    }

    public Userpharmacy(UserpharmacyPK userpharmacyPK) {
        this.userpharmacyPK = userpharmacyPK;
    }

    public Userpharmacy(UserpharmacyPK userpharmacyPK, boolean active) {
        this.userpharmacyPK = userpharmacyPK;
        this.active = active;
    }

    public Userpharmacy(int pharmacyId, int userId) {
        this.userpharmacyPK = new UserpharmacyPK(pharmacyId, userId);
    }

    public Userpharmacy(int pharmacyId, int userId, boolean active) {
    	this.active = active;
        this.userpharmacyPK = new UserpharmacyPK(pharmacyId, userId);
    }
    
    public UserpharmacyPK getUserpharmacyPK() {
        return userpharmacyPK;
    }

    public void setUserpharmacyPK(UserpharmacyPK userpharmacyPK) {
        this.userpharmacyPK = userpharmacyPK;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Collection<Transaction> getTransactionCollection() {
        return transactionCollection;
    }

    public void setTransactionCollection(Collection<Transaction> transactionCollection) {
        this.transactionCollection = transactionCollection;
    }

    public Collection<Transaction> getTransactionCollection1() {
        return transactionCollection1;
    }

    public void setTransactionCollection1(Collection<Transaction> transactionCollection1) {
        this.transactionCollection1 = transactionCollection1;
    }

    public Collection<Decline> getDeclineCollection() {
        return declineCollection;
    }

    public void setDeclineCollection(Collection<Decline> declineCollection) {
        this.declineCollection = declineCollection;
    }

    public Collection<Stock> getStockCollection() {
        return stockCollection;
    }

    public void setStockCollection(Collection<Stock> stockCollection) {
        this.stockCollection = stockCollection;
    }

    public Pharmacy getPharmacy() {
        return pharmacy;
    }

    public void setPharmacy(Pharmacy pharmacy) {
        this.pharmacy = pharmacy;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Collection<Accountreceivable> getAccountreceivableCollection() {
        return accountreceivableCollection;
    }

    public void setAccountreceivableCollection(Collection<Accountreceivable> accountreceivableCollection) {
        this.accountreceivableCollection = accountreceivableCollection;
    }

    public Collection<Transfer> getTransferCollection() {
        return transferCollection;
    }

    public void setTransferCollection(Collection<Transfer> transferCollection) {
        this.transferCollection = transferCollection;
    }

    public Collection<Transfer> getTransferCollection1() {
        return transferCollection1;
    }

    public void setTransferCollection1(Collection<Transfer> transferCollection1) {
        this.transferCollection1 = transferCollection1;
    }

    public Collection<Access> getAccessCollection() {
        return accessCollection;
    }

    public void setAccessCollection(Collection<Access> accessCollection) {
        this.accessCollection = accessCollection;
    }

    public Collection<Product> getProductCollection() {
        return productCollection;
    }

    public void setProductCollection(Collection<Product> productCollection) {
        this.productCollection = productCollection;
    }
/*
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userpharmacyPK != null ? userpharmacyPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Userpharmacy)) {
            return false;
        }
        Userpharmacy other = (Userpharmacy) object;
        if ((this.userpharmacyPK == null && other.userpharmacyPK != null) || (this.userpharmacyPK != null && !this.userpharmacyPK.equals(other.userpharmacyPK))) {
            return false;
        }
        return true;
    }

    @Override	*/
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Userpharmacy[ userpharmacyPK=" + userpharmacyPK + " ]";
    }
    
}
